<!-- extends表明此页面继承自 base.html 文件 -->
{% extends "base.html" %}
{% load staticfiles %}
<!-- 写入 base.html 中定义的 title -->
{% block title %}
    机构信息
{% endblock title %}
<!-- 写入 base.html 中定义的 content -->
{% block content %}
    <main class="section">
        <div class="columns is-multiline">
            <div class="column is-full">
                <div class="box columns has-background-primary">
                    <div class="column is-4">
                        <figure class="image is-16by9">
                            <img src="{{ MEDIA_URL }}{{ course_org.org_logo }}" alt="Image">
                        </figure>
                    </div>
                    <div class="column">
                        <p class="title is-2 has-text-white">{{ course_org.name }}</p>
                        <hr>
                        <p class="title is-4 has-text-white">
                            收藏数：{{ course_org.fav_nums }}
                        </p>
                        <p class="title is-4 has-text-white">
                            学生数：{{ course_org.students }}
                        </p>
                        <p class="title is-4 has-text-white">
                            课程数：{{ course_nums }}
                        </p>
                        <p class="title is-4 has-text-white">
                            点击数：{{ course_org.click_nums }}
                        </p>
                        <p class="title is-4 has-text-white">
                            地&nbsp;&nbsp;&nbsp;&nbsp;址：{{ course_org.address }}
                        </p>
                        <p class="title is-4 has-text-white">
                            <a class="has-text-link-light" id="fav" data-favid="22" data-fav-type="1">
                                <strong>
                                    {% if has_fav %}
                                        已&nbsp;&nbsp;收&nbsp;&nbsp;藏&nbsp;<i class="fa fa-star" aria-hidden="true"></i>
                                    {% else %}
                                        收&nbsp;&nbsp;&nbsp;&nbsp;藏&nbsp;<i class="fa fa-star-o" aria-hidden="true"></i>
                                    {% endif %}
                                </strong>
                            </a>
                        </p>
                    </div>
                    <div class="column is-2 is-centered">

                    </div>
                </div>
            </div>
            <div class="column is-full box">
                <div class="column is-full">
                    <div class="tabs is-centered is-medium">
                        <ul>
                            <li class="{% if nav_tab == "home" or nav_tab == "" %} is-active {% endif %}">
                                <a href="{% url 'org:home' course_org.id %}?nav_tab=home">
                                <span>
                                    <strong>
                                        机构首页
                                    </strong>
                                </span>
                                </a>
                            </li>
                            <li class="{% if nav_tab == "course" %} is-active {% endif %}">
                                <a href="{% url 'org:course' course_org.id %}?nav_tab=course">
                                <span>
                                    <strong>
                                        机构课程
                                    </strong>
                                </span>
                                </a>
                            </li>
                            <li class="{% if nav_tab == "teachers" %} is-active {% endif %}">
                                <a href="{% url 'org:teacher' course_org.id %}?nav_tab=teachers">
                                <span>
                                    <strong>
                                        机构讲师
                                    </strong>
                                </span>
                                </a>
                            </li>
                            <li class="{% if nav_tab == "desc" %} is-active {% endif %}">
                                <a href="{% url 'org:desc' course_org.id %}?nav_tab=desc">
                                <span>
                                    <strong>
                                        机构介绍
                                    </strong>
                                </span>
                                </a>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
            {% block content_org %}
            {% endblock %}
        </div>
    </main>
{% endblock %}

{% block content_js %}
    <script type="text/javascript">
        function add_fav(current_elem, fav_id, fav_type) {
            $.ajax({
                cache: false,
                type: "POST",
                url: "{% url 'op:fav' %}",
                data: {'fav_id': fav_id, 'fav_type': fav_type},
                async: true,
                beforeSend: function (xhr, settings) {
                    xhr.setRequestHeader("X-CSRFToken", "{{ csrf_token }}");
                },
                success: function (data) {
                    if (data.status == 'fail') {
                        if (data.msg == '用户未登录') {
                            window.location.href = "{% url 'login' %}";
                        } else {
                            alert(data.msg)
                        }

                    } else if (data.status == 'success') {
                        {#current_elem.text(data.msg)#}
                        alert(data.msg)
                        window.location.reload()
                    }
                },
            });
        }

        $(document).ready(function () {
            $('#fav').on('click', function () {
                add_fav($(this), {{ course_org.id }}, 2);
            });
        });
    </script>
{% endblock content_js %}
